<?php
session_start();
include("../common/connect.php");
include("../common/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = CheckUrlParamNoDie("showtype");
$tag = CheckUrlParamNoDie("tag");
$gid = CheckUrlParamNoDie("gid");
$nPage = CheckUrlParamNoDie("page");

if ($nPage == "") $nPage = 1;
if(isset($_POST["Site_Submit"]))
{
	$tdhtitle = trim(GetPostParamStr("dhtitle"));
	$tdhpic = trim(GetPostParamStr("dhpic"));
	$tdhfee = trim(GetPostParamStr("dhfee"));
	$tdhnumber = trim(GetPostParamStr("dhnumber"));
	$ttumoney = trim(GetPostParamStr("tumoney"));
	$tdhtag = trim(GetPostParamStr("dhtag"));
	$tdhintr = trim(GetPostParamStr("dhintr"));
	
	if($gid != "")
	{
		$sql2 = "update gwt_dh_goods set dhtitle='$tdhtitle', dhpic='$tdhpic', dhfee=$tdhfee, dhnumber=$tdhnumber, tumoney=$ttumoney, dhintr='$tdhintr', dhtag='$tdhtag' where id=$gid";
		mysql_query($sql2);
		if (mysql_affected_rows() == 1)
			echo "<script>window.history.go(-2);</script>";
	}else{
		$sql = "insert into gwt_dh_goods (dhtitle,dhpic,dhfee,dhnumber,tumoney,dhintr,dhtag) values ('$tdhtitle', '$tdhpic',$tdhfee, $tdhnumber, $ttumoney, '$tdhintr', '$tdhtag')";
		mysql_query($sql);
		echo "<script>window.history.go(-2);</script>";
	}
}

if ($opt == "del" && $gid != "")
{
	mysql_query("delete from gwt_dh_goods where id=$gid");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}
$row = mysql_fetch_assoc(mysql_query("select count(*) as tmp from gwt_dh_goods"));
$allCount = $row["tmp"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>商品管理-兑换商城中心管理</title>
<style type="text/css">
body {font-size: 12px;color: #000;font-family: 宋体;}
.STYLE1 {font-size: 13px;font-weight: bold;}
table {border-collapse:collapse; border-spacing:2px;  font-size:12px;}
td,th { display:table-cell; vertical-align:inherit;}
img { border:0; vertical-align:top;}
a { color:#00F;}
/***网站提交***/
.Unbound { background:#f2eeef; width:555px; padding:10px; position:absolute; top:10px; left:240px; font-size:12px;}
.Unbound .unss { background:#FFF; padding:10px; border:1px solid #999;}
.Unbound .sel { height:30px; border-bottom:1px solid #ddd;}
.Unbound .sel .Close a { float:right; text-indent:0; width:40px; display:inline-block;}
.Unbound .ted { overflow:hidden;}
.Unbound .ted .ted_tj { margin-top:10px; clear:both; overflow:hidden;}
.Unbound .ted .ted_tj span { width:90px; text-align:right; display:block; float:left;}
.Unbound .ted .ted_tj .tedinp,.Unbound .ted .ted_tj textarea { height:22px; line-height:22px; border:1px solid #ddd; font-size:12px; padding:0 5px; color:#666; overflow:hidden;}
.Unbound .ted .ted_tj select.tedinp { padding:0;}
.Unbound .ted .ted_tj textarea { width:360px; height:70px; }
.Unbound .ted .sz_btn { margin:20px auto; width:133px; overflow:hidden;}
.Unbound .ted .sz_btn input { background:url(http://www.gouwutu.com/new/doc/img/sebtn.jpg) no-repeat; cursor:pointer; padding:0; color:#FFF; font-weight:bold; width:133px; height:45px; border:0;}
/*********/
#pu_dht { margin:10px auto; text-align:center; width:100%;}
#pu_dht a,#pu_dht b { background-color:#F4D662; border:1px solid #F90; color:#fff; display:inline-block; font-size:12px; height:22px; line-height:22px; margin:0 1px; min-width:12px; padding:0 4px; white-space:nowrap; text-align:center;}
#pu_dht a { color:#F90; background-color:#FFF;}
#pu_dht a:hover {background-color:#F4D662;color:#fff;}
</style>
<script language="javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "dhcenter.php?showtype=" + input_tradeid + "&tag=" + site_tag ;
}
function sunbmintSS()
{
	var dhtitle = document.getElementById("dhtitle").value;
	var dhpic = document.getElementById("dhpic").value;
	//var dhfee = document.getElementById("dhfee").value;
	var dhnumber = document.getElementById("dhnumber").value;
	var tumoney = document.getElementById("tumoney").value;
	var dhtag = document.getElementById("dhtag").value;
	var dhintr = document.getElementById("dhintr").value;
	
	if (dhtitle == "" && dhpic == "" && dhnumber == "" && tumoney == "" && dhtag == "" && dhintr == "")
	{
		alert("请确定你没有漏填的~");
     	return false;
     }
	 
	return true;
}
</script>
</head>
<body>
<div style="">
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#a8a8a8">
	<tr>
    	<td height="40" align="center" colspan="9"><font size="+2">兑换商城管理中心</font>商品信息管理</td>    
    </tr>
    <tr height="30" align="center" bgcolor="#00FF99">
    	<td colspan="9"><a href="dhcenter.php" style="color:#F00">商品信息管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="order.php">订单信息管理</a></tr>
    </tr>
    <tr>
    	<td height="30" colspan="9">&nbsp;&nbsp;&nbsp;&nbsp;
        	<select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
          		<option value="1" selected='selected'>商品编码</option>
          		<option value="2">商品名称</option>
        	</select>&nbsp;&nbsp;
        	<input type="text" size="20" id="showtype" name="showtype" value="">&nbsp;&nbsp;
            <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="dhcenter.php">默认显示</a>&nbsp;&nbsp;<a href="?opt=edit"><font color="#FF0000">添加商品</font></a>
     	</td>
    </tr>
    <tr align="center" bgcolor="#66CCFF">
    	<td  width="60" height="30">商品编码</td>
        <td>商品名称</td>
        <td width="200">商品图片</td>
        <td width="50">价格</td>
        <td width="100">数量</td>
        <td width="100">兑换兔币</td>
        <td width="50">分类</td>
        <td width="300">商品简介</td>
        <td width="100">操作</td>
    </tr>
    <?php
	$PAGE_SIZE = 10; //每页数量
	$limit = " limit ". ($nPage-1)*$PAGE_SIZE .",$PAGE_SIZE";
	$sql = "";
	if($showtype != "" && $tag == "1")
		$sql .= " where id=$showtype";
	else if($showtype != "" && $tag == "2")
		$sql .= " where dhtitle=$showtype";
		
    $sql = "select * from gwt_dh_goods".$sql." order by id asc".$limit;
	//echo $sql;
	$result = mysql_query($sql);
	$i = 0;
	while( $result && $row = mysql_fetch_assoc($result))
	{
	?>
	<tr align="center">
    	<td><?php echo $row["id"]; ?></td>
        <td><?php echo $row["dhtitle"]; ?></td>
        <td><img src="<?php echo $row["dhpic"]; ?>" height="100" /></td>
        <td><?php echo $row["dhfee"]; ?></td>
        <td><?php echo $row["dhnumber"]; ?></td>
        <td><?php echo $row["tumoney"]; ?></td>
        <td><?php echo $row["dhtag"]; ?></td>
        <td align="left"><p style="width:290px; padding-left:10px; line-height:20px;max-height:100px; text-align:left; overflow-y:scroll;"><?php echo $row["dhintr"]; ?></p></td>
        <td><a href="?opt=edit&gid=<?php echo $row["id"]; ?>">编辑</a>&nbsp;&nbsp;<a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&gid=<?php echo $row["id"]; ?>'">删除</a></td>
    </tr>
    <?php } ?>
    <tr>
    	<td colspan="9">
        	<div id="pu_dht">
            <?PHP if ($allCount > $PAGE_SIZE) { ?>
				<div id="Pager1">
				 <?php	
                    $all_page = ceil($allCount / $PAGE_SIZE);
                    if ($nPage > 1) echo "<a class='pageNext' href='?page=".($nPage-1)."'>上一页</a>";
                    
                    if($all_page<=12){				
                        for($i=1;$i<=$all_page;$i++){//数字分页
                            $Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
                            echo $Pageshow;
                        }
                    }else{
                        for($i=1;$i<=12;$i++){//数字分页
                            $Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
                            echo $Pageshow;
                        }
                    }
                    
                    if($nPage == 12 || $nPage == $all_page){
                        echo "";
                    }else if($nPage < 12){
                        echo "<a class='pageNext' href='?page=".($nPage+1)."'>下一页</a>";
                    }
                     ?>
                </div>
            <?php
			}
			?>                          
        	</div>
        </td>
    </tr>
</table>
<?php
if($opt == "edit")
{
	$dhtitle = "";
	$dhpic = "";
	$dhfee = "";
	$dhnumber = "";
	$tumoney = "";
	$dhtag = "";
	$dhintr = "";
	
	if( $gid != "" )
	{
		$esql = "select * from gwt_dh_goods where id=$gid limit 1";
		$eresult = mysql_query( $esql );
		if( $eresult && $row2 = mysql_fetch_assoc( $eresult ) )
		{
			$dhtitle = $row2["dhtitle"];
			$dhpic = $row2["dhpic"];
			$dhfee = $row2["dhfee"];
			$dhnumber = $row2["dhnumber"];
			$tumoney = $row2["tumoney"];
			$dhtag = $row2["dhtag"];
			$dhintr = $row2["dhintr"];
		}
	}
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="dhcenter.php">关闭</a></span>编辑/添加</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="dhcenter.php?gid=<?php echo $gid; ?>">
                <div class="ted_tj"><span>商品名称：</span><input type="text" value="<?php echo $dhtitle; ?>" name="dhtitle" id="dhtitle" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>商品图片：</span><input type="text" value="<?php echo $dhpic; ?>" name="dhpic" id="dhpic" style="width:390px;"></div>
                <div class="ted_tj">
                	<p style="float:left;"><span>市场价格：</span><input type="text" value="<?php echo $dhfee; ?>" name="dhfee" id="dhfee"style="width:60px;" class="tedinp"></p>
                    <p style="float:left;"><span>商品数量：</span><input type="text" value="<?php echo $dhnumber; ?>" name="dhnumber" id="dhnumber"style="width:60px;" class="tedinp"></p>
                    <p style="float:left;"><span>兑换兔币：</span><input type="text" value="<?php echo $tumoney; ?>" name="tumoney" id="tumoney" style="width:60px;" class="tedinp"></p>
             	</div>
                <div class="ted_tj" id="WZ"><span>网站类型：</span><select size="1" id="dhtag" name="dhtag" class="tedinp">
                	<option value="<?php echo $dhtag; ?>"><?php echo $dhtag; ?></option>
                    <option value="热门推荐">热门推荐</option>
                    <option value="电子数码">电子数码</option>
                    <option value="家居礼品">家居礼品</option>
                    <option value="生活实用">生活实用</option>
                    <option value="虚拟产品">虚拟产品</option>
                    <option value="真情回馈">真情回馈</option>
                </select>
                &nbsp;&nbsp;&nbsp;<font color="#FF0000">商品简介如果要换行的话请加一个&lt;br /&gt;</font>
                </div>
                <div class="ted_tj"><span>商品简介：</span><textarea id="dhintr" name="dhintr" style="padding-right:20px; overflow-y:scroll; overflow-x: auto; box-sizing: border-box;"><?php echo $dhintr; ?></textarea></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</div>
</body>
</html>
